package com.xcity.pomelo.response;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.xcity.game.activity2.circle.CircleRewardTemplate;
import com.xcity.game.item.ItemTemplate;

import naga.x.App;
import naga.x.game.template.TemplateService;
import naga.x.net.impl.pomelo.PomeloMessage;
import naga.x.net.impl.pomelo.protocol.Message;
import naga.x.util.TimeUtils;

@PomeloMessage(type = Message.Type.RESPONSE)
public class ActivityCircleInfoResponse extends Response {

	private int curScore;
	private int curFreeCount;
	private List<CircleSampleInfo> list;
	private int rankActive;
	private int shopActive;
//	private String startStr;
	private String endStr;

	public static class CircleSampleInfo{
		public int id;
		public int type;
		public String rewardName;
		public String rewardIcon;
		public int rewardCount;
		public CircleSampleInfo(CircleRewardTemplate temp, String rewardName, String rewardIcon){
			this.id = temp.getId();
			this.type = temp.getType();
			this.rewardCount = temp.getRewardCount();
			this.rewardName = rewardName;
			this.rewardIcon = rewardIcon;
		}
	}
	
	public ActivityCircleInfoResponse(int serial, List<CircleRewardTemplate> rewardList, int score, int freeCount, boolean rankActive, boolean shopActive, Date endTime) {
		super(serial);
		this.curScore = score;
		this.curFreeCount = freeCount;
		TemplateService ts = App.getApp().getServiceManager().get(TemplateService.class);

		this.list = new ArrayList<CircleSampleInfo>();
		for(int i = 0; i < rewardList.size(); i++){
			ItemTemplate itemTemp = null;
			CircleRewardTemplate rewardTemp = rewardList.get(i);
			String rewardName = null;
			String rewardIcon = null;
			switch (rewardTemp.getType()) {
			case 1://金钱
				rewardName = "金钱";
				rewardIcon = rewardTemp.getRewardIcon();//TODO 金钱图标
				break;
			case 2://物品
				itemTemp = ts.get(ItemTemplate.class, rewardTemp.getRewardId());
				rewardIcon = rewardTemp.getRewardIcon();
				if(itemTemp != null){
					rewardName = itemTemp.getName();
					rewardIcon = itemTemp.getIcon();
				}
				break;
			}
			CircleSampleInfo sampleInfo = new CircleSampleInfo(rewardTemp, rewardName, rewardIcon);
			this.list.add(sampleInfo);
		}
		this.rankActive = rankActive?1:0;
		this.shopActive = shopActive?1:0;
		this.endStr = TimeUtils.format("yyyy年MM月dd日24时", endTime);
	}

	public int getCurScore() {
		return curScore;
	}

	public void setCurScore(int curScore) {
		this.curScore = curScore;
	}
	public int getCurFreeCount() {
		return curFreeCount;
	}

	public void setCurFreeCount(int curFreeCount) {
		this.curFreeCount = curFreeCount;
	}
	
	public List<CircleSampleInfo> getList() {
		return list;
	}

	public void setList(List<CircleSampleInfo> list) {
		this.list = list;
	}

	public int getRankActive() {
		return rankActive;
	}

	public void setRankActive(int rankActive) {
		this.rankActive = rankActive;
	}
	
	public int getShopActive() {
		return shopActive;
	}
	
	public void setShopActive(int shopActive) {
		this.shopActive = shopActive;
	}

//	public String getStartStr() {
//		return startStr;
//	}
//
//	public void setStartStr(String startStr) {
//		this.startStr = startStr;
//	}

	public String getEndStr() {
		return endStr;
	}

	public void setEndStr(String endStr) {
		this.endStr = endStr;
	}
}
